package com.hurl.waguji.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.ScrollableResults;

import com.hurl.library.util.StringUtils;
import com.hurl.waguji.base.SqlReader;
import com.hurl.waguji.base.dao.HibernateDao;
import com.hurl.waguji.base.dao.HibernateService;
import com.opensymphony.xwork2.ActionSupport;

public class NavigatorAction extends ActionSupport{
	private List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
	private String node;
	
	
	public String getNode() {
		return node;
	}

	public void setNode(String node) {
		this.node = node;
	}

	public List<Map<String,Object>> getList() {
		return list;
	}

	public void setList(List<Map<String,Object>> list) {
		this.list = list;
	}

	@Override
	public String execute() throws Exception {
		if(StringUtils.isBlank(node)){
			node = "root";
		}

		HibernateDao dao = HibernateService.getDao();
		ScrollableResults results = dao.queryBySQL(SqlReader.getSql("SQL000003",new String[]{node})).scroll();
		while(results.next()){
			results.get(0);
			Map<String,Object> map = new HashMap<String,Object>();
			map.put("id", (String)results.get(0));
			map.put("text", (String)results.get(1));
			map.put("url", (String)results.get(2));
			map.put("leaf", (Boolean)results.get(3));
			list.add(map);
		}
		
		return SUCCESS;
	}
	
}
